Computer database systems manage the storage and retrieval of data in a database. A database comprises a set of tables of data along with information about relations between the tables. Tables represent relations over the data. Each table comprises a set of records of data stored in one or more data fields. The records of a table are also referred to as rows, and the data fields of records in a table are also referred to as columns.
A database server processes data manipulation statements or queries, for example, to retrieve, insert, delete, and modify data in a database. Queries are defined by a query language supported by the database system. To enhance performance in processing queries, database servers use information about the data distribution to help access data in a database more efficiently. Typical servers comprise a query optimizer which estimate the selectivity of queries and generate efficient execution plans for queries. Query optimizers generate execution plans based on he query and in doing so exploits statistical information on the column(s) of the table(s) referenced in the queries.
Database servers may create histograms on the columns of tables to represent the distribution of a data. A histogram is one means of representing the distribution of data in a database. A histogram on a data attribute consists generally of a set of partitions or boundaries which divide the range of data on the attribute into a set of segments or buckets. Also associated with each bucket is a frequency which corresponds to the number of data tuples which fall within the boundaries of the bucket. The frequency associated with a bucket, or bucket frequency, is an indication of the density of data within the bucket's boundaries, and should not be confused with the absolute value of the data within the bucket.
The accuracy of the estimations of the query optimizer are enhanced by the availability of histograms, however, creating and maintaining histograms can incur significant costs, particularly for large databases. This problem is particularly striking for multi-dimensional histograms that capture joint distributions of correlated data attributes. Although multi-dimensional histograms can be highly valuable, the relatively high cost of building and maintaining them often prevents their use.
Query optimization in relational database systems has traditionally relied on single-attribute histograms to compute the selectivity of queries. For queries that involve multiple attributes, most database systems make the attribute value independence assumption, i.e., assume that Prob(A1=v1,A2=v2)=Prob(A1=v1)×Prob(A2=v2), which may of course lead to significant inaccuracy in selectivity estimation.
An alternative to assuming attribute value independence is to use histograms over multiple attributes, which are generally referred to as multidimensional histograms. Ideally, multidimensional histograms should consist of buckets that enclose regions of the data domain with close-to-uniform tuple density. At the same time, multidimensional histograms should be sufficiently compact and efficiently computable. Unfortunately, existing multidimensional histogram construction techniques fail to satisfy these requirements robustly across data distributions.
Several techniques exist in the literature to compute selectivity estimators of multidimensional data sets. These techniques include wavelets and discrete cosine transformations, sampling, and multidimensional histograms. The V-optimal(f,f) family of histograms groups contiguous sets of frequencies into buckets and minimizes the variance of the overall frequency approximation. These histograms work well for estimating the result size of tree, function tree, equality join, and selection queries under a definition of optimality that captures the average error over all possible queries and databases. However, these histograms need to record every distinct attribute value inside each bucket, which is impractical. Moreover, the construction algorithm involves an exhaustive and exponential enumeration of all possible histograms. A more practical approach is to restrict the attention to V-optimal(v,f) histograms, which group contiguous sets of values into buckets, minimizing the variance of the overall frequency approximation. A dynamic programming algorithm has been presented for building unidimensional V-optimal(v,f) histograms in O(N2b) time, where N is the number of tuples in the data set and b is the desired number of buckets. However, even for two-dimensional data sets, building the V-optimal(v,f) histogram using arbitrary rectangular buckets is NP-Hard. Therefore, practical static multidimensional histogram techniques use heuristics to partition the data space into buckets.
A multidimensional version of the Equi-Depth histogram recursively partitions the data domain into buckets with the same frequency, one dimension at a time. A technique called Mhist is based on MaxDiff(v,a) histograms in which the data domain is iteratively partitioned using a greedy procedure. In each step, MaxDiff(v,a) identifies the bucket in most need of partitioning and splits it along the dimension with the highest difference in frequency between consecutive values. GenHist histograms allow unrestricted overlap among buckets. If more than two buckets overlap, the density of tuples in their intersection is approximated as the sum of the data densities of the overlapping buckets. For the technique to work, a tuple that lies in the intersection of many buckets is counted in only one of them (chosen probabilistically). Progressively coarser grids are constructed over the data set and the densest cells are converted into buckets of the histogram. A certain percentage of tuples in those cells is removed to make the resulting distribution smoother.
The above discussed histogram techniques are static in the sense that after the histograms are built, their buckets and frequencies remain fixed regardless of any changes in the data distribution. One technique decides when reorganization is needed by using thresholds that depend on the number of updates over the relation or the accuracy of the histogram. For example, if the average estimation error is above a given value, the whole histogram is discarded and rebuilt from scratch. Some techniques consider histogram refinement as an alternative to periodic reconstruction. One such technique maintains a backing sample and an approximate Equi-Depth histogram in memory. During insertions and deletions, both the sample and the histogram are updated. When the Equi-Depth constraint that all bucket frequencies should be equal is violated beyond a given threshold, some buckets are split and others are merged to restore the Equi-Depth constraint. If no reorganization can restore the constraint, the existing histogram is discarded and a new one is built from the sample. Another technique considers dynamic compressed histograms that store some values in singleton or singular buckets, while the rest are partitioned using Equi-Depth into regular buckets. The general idea is to relax histogram constraints up to a certain point, after which the histogram is reorganized so that it satisfies the constraints. For dynamic compressed histograms, a χ2 test is used to determine when to reorganize. This restructuring uses promotion from singular to regular buckets, degradation from regular to singular buckets, and redistribution of the remaining regular buckets as the only operations. These histogram techniques deal only with unidimensional data.
One parametric technique for approximating data distributions that uses feedback from the query execution engine represents the data distribution as a linear combination of model functions. The weighting coefficients of this linear combination are adjusted using feedback information and a least squares technique. This technique is dependent on the choice of model functions and assumes that the data follows some smooth and known distribution. STGrid histograms use query feedback to refine buckets. An STGrid histogram greedily partitions the data domain into disjoint buckets that form a grid, and refines their frequencies using query feedback. After a predetermined number of queries, the histogram is restructured by merging and splitting rows of buckets one at a time (to preserve the grid structure). Accuracy is traded for efficiency in histogram tuning, a goal of this technique. Since STGrid histograms need to maintain the grid structure at all times, and due to the greedy nature of the technique, some locally beneficial splits and merges have the side effect of modifying distant and unrelated regions, hence decreasing the overall accuracy.